package demo;

import demo.chef.AbstractChef;
import demo.chef.impl.MrWangChef;
import demo.chef.impl.TomChef;
import demo.chef.impl.WuYongChef;
import demo.dishes.AbstractDishes;

import java.util.HashSet;
import java.util.Set;

/**
 * 利用享元模式设计厨房
 * @author ZhouWeiBo
 * @create 2022/6/7
 */
public class Kitchen {
    private static Kitchen kitchen = new Kitchen();
    private Set<AbstractChef> chefs = new HashSet<>();

    private Kitchen() {
        chefs.add(new MrWangChef(1,CuisinesStyle.CHINESE_CUISINES));
        chefs.add(new TomChef(2,CuisinesStyle.FRENCH_CUISINES));
        chefs.add(new WuYongChef(3,CuisinesStyle.TURKISH_CUISINES));
    }

    private Kitchen(Set<AbstractChef> chefs) {}

    public static Kitchen getInstance(){
        return kitchen;
    }

    public boolean chef2Cook(AbstractDishes dishes){
        CuisinesStyle style = dishes.getCuisinesStyle();
        for (AbstractChef c : chefs){
            if (c.getStatus() == 0 && c.getCuisinesStyles() == style){
                c.cooking(dishes);
                return true;
            }
        }
        return false;
    }
}
